#include "mediaplay.h"
#include "ui_mediaplay.h"
#include<QFileDialog>
#include<QMediaPlayer>
#include<QMediaPlaylist>
#include<QVideoWidget>
#include<QPaintEvent>
#include<QStringList>

mediaplay::mediaplay(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::mediaplay)
{
    ui->setupUi(this);
    this->setWindowTitle("墩墩影视");
    player=new QMediaPlayer(this);
    list=new QMediaPlaylist(this);
    playwidget =new QVideoWidget(ui->label);
    playwidget->resize(ui->label->size());
    player->setPlaylist(list);
    player->setVideoOutput(playwidget);
}

mediaplay::~mediaplay()
{
    delete ui;
}

void mediaplay::on_pushButton_clicked()
{
    QStringList paths=QFileDialog::getOpenFileNames(this,"open media","D:/QTcode/BingDwenDwen/media_new","all(*.*);;"
                                                                            "mp4(*.mp4)");
    list->clear();
    foreach(QString const & str,paths){
        QUrl url(str);
        list->addMedia(url);
    }
}


void mediaplay::on_pushButton_2_clicked()
{
    player->play();
    playwidget->resize(ui->label->size());
}

void mediaplay::on_pushButton_3_clicked()
{
    player->pause();
}


void mediaplay::on_pushButton_4_clicked()
{
    player->stop();
}
void mediaplay::paintEvent(QPaintEvent*){
    playwidget->resize(ui->label->size());
}
void mediaplay::closeEvent(){
    player->stop();
}
